$(document).ready(function () {
  var obj = GetRequest();
  getUrlParamValue(name);
  console.log(obj.name);
  var orgname = obj.name + "卫生院";
  $("#xiangnameId").text(orgname);
  rizhimingxiFun(orgname);
  jiuzhenpaihangFun(orgname);
});
//返回上一页
function retrunPage() {
  goprevPage();
}
function init() {
  //   getData();
}

// 获取参数
// function getData() {

// }
//根据参数名称获取url参数
function getUrlParamValue(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return decodeURIComponent(r[2]);
  return null;
}
//获取url参数封装成对象
function GetRequest() {
  var url = location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = decodeURIComponent(
        strs[i].split("=")[1]
      );
    }
  }
  return theRequest;
}

//日志明细
function rizhimingxiFun(orgname) {
  console.log(server + "/" + orgname);
  $.ajax({
    type: "get",
    url: server + "/daping-gw/getMenZenRiZhi2.do?orgname=" + orgname,
    // data: "name=John&location=Boston",
    success: function (msg) {
      console.log("Data Saved: " + msg);
      var data = JSON.parse(msg);
      var dataArr = data.xzrizhi;
      var html = "";
      $.each(dataArr, function (x, y) {
        // console.log(y.doctorname);

        html += "<ul class='rightWrapBottomUlBg'>";
        html += "<li>" + y.num + "</li>";
        html += "<li>" + y.kzdoctor + "</li>";
        html += "<li>" + y.hzname + "</li>";
        html += "<li>" + y.sex + "</li>";
        html += "<li>" + y.age + "</li>";
        html += "<li>" + y.kzleixing + "</li>";
        html += "<li>" + y.kzdata + "</li>";
        html += "<li>" + y.zdname + "</li>";
        html += "</ul>";
      });
      $("#rightWrapBottomUlId").append(html);
    },
  });
}

//就诊排行
function jiuzhenpaihangFun(orgname) {
  var myChart = echarts.init(document.getElementById("jiuzhenpaihangId"));
  $.ajax({
    type: "get",
    url: server + "/daping-gw/getJiuZenSort2.do?orgname=" + orgname,

    // data: "name=John&location=Boston",
    success: function (msg) {
      console.log("Data Saved: " + msg);
      var data = JSON.parse(msg);
      var dataArr = data.xzjiuzensort;
      if (dataArr.length !== 0) {
        var dataArr = data.xzjiuzensort;
        var diagnameTextA = dataArr[0].diagname;
        var diagnameNumberA = dataArr[0].num1;
        var diagnameTextB = dataArr[1].diagname;
        var diagnameNumberB = dataArr[1].num1;
        var diagnameTextC = dataArr[2].diagname;
        var diagnameNumberC = dataArr[2].num1;
        var diagnameTextD = dataArr[3].diagname;
        var diagnameNumberD = dataArr[3].num1;
        var diagnameTextE = dataArr[4].diagname;
        var diagnameNumberE = dataArr[4].num1;
        var diagnameTextF = dataArr[5].diagname;
        var diagnameNumberF = dataArr[5].num1;
        var diagnameTextG = dataArr[6].diagname;
        var diagnameNumberG = dataArr[6].num1;
        var diagnameTextH = dataArr[7].diagname;
        var diagnameNumberH = dataArr[7].num1;
        var diagnameTextI = dataArr[8].diagname;
        var diagnameNumberI = dataArr[8].num1;
        var diagnameTextJ = dataArr[9].diagname;
        var diagnameNumberJ = dataArr[9].num1;
        var myColor = [
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
          "#1089E7",
          "#F57474",
          "#56D0E3",
          "#F8B448",
          "#8B78F6",
        ];
        $.each(dataArr, function (x, y) {
          // arrillS.push(y.diagname);
          // arrNumberS.push(y.num1);
          // arrOrgname.push(y.orgname);

          option = {
            // tooltip: {
            //   trigger: "axis",
            //   axisPointer: {
            //     type: "shadow",
            //   },
            // },

            grid: {
              left: "20%",
              right: "12%",
              bottom: "5%",
              top: "10%",
              containLabel: false,
            },
            // 不显示x轴信息
            xAxis: {
              show: false,
            },
            // 不显示y轴线和相关刻度
            yAxis: [
              {
                type: "category",
                inverse: true,
                data: [
                  diagnameTextA,
                  diagnameTextB,
                  diagnameTextC,
                  diagnameTextD,
                  diagnameTextE,
                  diagnameTextF,
                  diagnameTextG,
                  diagnameTextH,
                  diagnameTextI,
                  diagnameTextJ,
                ],
                axisLine: {
                  show: false,
                },
                axisTick: {
                  show: false,
                },
                axisLabel: {
                  color: "#fff",
                  fontSize: 10,
                },
              },
              {
                type: "category",
                inverse: true,
                data: [
                  diagnameNumberA,
                  diagnameNumberB,
                  diagnameNumberC,
                  diagnameNumberD,
                  diagnameNumberE,
                  diagnameNumberF,
                  diagnameNumberG,
                  diagnameNumberH,
                  diagnameNumberI,
                  diagnameNumberJ,
                ],
                axisLine: {
                  show: false,
                },
                axisTick: {
                  show: false,
                },
                axisLabel: {
                  color: "#fff",
                  fontSize: 10,
                },
              },
            ],
            series: [
              {
                name: "条",
                type: "bar",
                barCategoryGap: 20,
                barWidth: 7,
                yAxisIndex: 0,
                itemStyle: {
                  barBorderRadius: 20,
                  color: function (params) {
                    // console.log(params);
                    return myColor[params.dataIndex];
                  },
                },
                data: [
                  diagnameNumberA,
                  diagnameNumberB,
                  diagnameNumberC,
                  diagnameNumberD,
                  diagnameNumberE,
                  diagnameNumberF,
                  diagnameNumberG,
                  diagnameNumberH,
                  diagnameNumberI,
                  diagnameNumberJ,
                ],
              },
              {
                name: "框",
                type: "bar",
                barCategoryGap: 20,
                barWidth: 12,
                yAxisIndex: 1,
                itemStyle: {
                  color: "none",
                  borderColor: "#00c1de",
                  borderWidth: 3,
                  barBorderRadius: 15,
                },
                data: [
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                  1000,
                ],
              },
            ],
          };

          myChart.setOption(option);
          window.addEventListener("resize", function () {
            myChart.resize();
          });
        });
      } else {
        alert("无就诊人数");
      }
    },
  });
}
